package com.example.imooccommon.service.constsservice;

import com.example.imooccommon.entity.consts.ConstsSiteCarousel;
import com.example.imooccommon.repository.constsrepository.ConstsSiteCarouselRepository;
import com.example.imooccommon.store.QiniuStorage;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;


import java.util.List;

/**
 * @Author Anita
 * @Date 2018/1/22 11:20
 */
@Service
public class ConstsSiteCarouselServiceImpl {


    @Autowired
    private ConstsSiteCarouselRepository constsSiteCarouselRepository;
    @Autowired
    private QiniuStorage qiniuStorage;

    public List<ConstsSiteCarousel> queryCarousel(Integer count){
        Pageable pageable = new PageRequest(0, count);
        Page<ConstsSiteCarousel> resultList = constsSiteCarouselRepository.findAll(pageable);
        List<ConstsSiteCarousel> constsSiteCarouselList = resultList.getContent();
        //处理为七牛图片链接
        for(ConstsSiteCarousel item: constsSiteCarouselList){
            item.setUrl(qiniuStorage.getUrl(item.getPicture()));
        }
        return constsSiteCarouselList;
    }
}
